<!DOCTYPE html>
<html>
<head>
    <include file="./Application/Home/View/Tpl/head.html" />
</head>
<body  class="fixed-header theme-blue-gradient">
<div   id="theme-wrapper">
    <include file="./Application/Home/View/Tpl/header.html" />

    <div id="page-wrapper" class="container">
        <div class="row">
            <include file="./Application/Home/View/Tpl/menu.html"/>

            <div id="content-wrapper">
                <BR>
                <div class="row">
                    <include file="./Application/Home/View/Tpl/alert.html"/>

                    <div class="col-md-12">
                        <div class="nav-tabs-custom">
                            <ul class="nav nav-tabs">
                                <li class="active" ><a href="#phone" data-toggle="tab">终端上网行为
                                    <empty name="userinfo">
                                        <small class="label pull-right label-success">0台</small>
                                        <else />
                                        <small class="label pull-right label-success scanwifidata"> {:count($userinfo)}台</small>
                                    </empty>

                                </a></li>
                            </ul>
                            <div class="tab-content">
                                <div class="tab-pane active" id="phone">

                                    <div class="post">
                                        <div class="col-xs-12" style="    background: #ffffff;">
                                            <!-- <BR>
                                            <div  class="col-md-4 pull-right">
                                                <div class="input-group  ">
                                                    <input type="text" class="form-control" id="filtertxt">
                                                    <span class="input-group-btn">
                                                  <button class="btn btn-info btn-flat"  id="search" type="button">搜索</button>
                                                </span>
                                                </div>
                                            </div>

                                            <BR>
                                            <BR>-->
                                            <div class="box" id="stalist">

                                                <empty name="userinfo">
                                                    尚未捕获到任何手机终端。
                                                    <else />
                                                    <!-- /.box-header -->
                                                    <div class="box-body table-responsive no-padding">
                                                        <table id="nettable" class="nettable table table-hover">
                                                            </table>
                                                    </div>
                                                </empty>
                                                <!-- /.box-body -->
                                            </div>
                                            <!-- /.box -->
                                        </div>
                                        <!-- /.user-block -->
                                        <p> &nbsp;
                                        </p>
                                        <ul class="list-inline">
                                        </ul>

                                    </div>
                                </div>
                                <!-- /.post -->
                                <BR>
                            </div>
                            <!-- /.tab-pane -->


                        </div>
                        <!-- /.tab-content -->
                    </div>
                </div>
                <div class="modal   fade"  id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                    <div class="modal-dialog" style="width: 100%;;margin: 0px">
                        <div class="modal-content" >
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                                <h4 class="modal-title" id="myModalLabel">关键信息监控</h4>
                            </div>
                            <div class="modal-body" id="stainfotr" style="min-height: 380px;">

                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-success  btn-lg" data-dismiss="modal">关 闭</button>
                            </div>
                        </div><!-- /.modal-content -->
                    </div><!-- /.modal -->
                </div>


                <div class="modal   fade"  id="myModalUrl" tabindex="-1" role="dialog" aria-labelledby="myModalLabelurl" aria-hidden="true">
                    <div class="modal-dialog" style="width: 100%;margin: 0px">
                        <div class="modal-content">
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                                <h4 class="modal-title" id="myModalLabelurl">上网行为监控</h4>
                            </div>
                            <div class="modal-body" id="urlinfotr"  style="min-height: 380px;">

                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-success  btn-lg" data-dismiss="modal">关 闭</button>
                            </div>
                        </div><!-- /.modal-content -->
                    </div><!-- /.modal -->
                </div>

                <include file="./Application/Home/View/Tpl/footer.html"/>

            </div>
        </div>

    </div>







</div>
<!-- ./wrapper -->

<include file="./Application/Home/View/Tpl/commjs.html" />
<script src="__PUBLIC__/datatable/datatables.min.js"></script>
<script src="__PUBLIC__/datatable/dataTables.bootstrap.js"></script>
<link rel="stylesheet" type="text/css" href="__PUBLIC__/datatable/buttons/css/buttons.bootstrap4.min.css">
<script src="__PUBLIC__/datatable/buttons/js/dataTables.buttons.js"></script>
<script src="__PUBLIC__/datatable/buttons/js/jszip.min.js"></script>
<script src="__PUBLIC__/datatable/buttons/js/buttons.html5.min.js"></script>
<script type="text/javascript">
    $(function(){
        var table = $('#nettable').DataTable({
            "stateSave": true,
            responsive: true,
            "deferRender": true,
            "bAutoWidth":true,

            "ajax": {
                "url": "{:U('/Home/Netlog/getdata','',false)}",
                "type": "POST",
                "deferRender": true
            },
            "columns": [
                {"data": "ip", },
                {"data": "mac"  },
                {"data": "term_id" },
                {"data": "", width:"25%"}
            ],
            "aoColumnDefs":[
                {
                    "aTargets": 3,
                    "mRender": function (data, type,row) {
                        console.log(row);
                        return '<button class="btn   btn-default getapsta"'+
                        'mac="'+row.mac+'"'+
                        'data-toggle="modal" data-target="#myModal">'+
                         '   <i class="fa fa-eye"></i> 关键信息监控'+
                         '   </button>'+
                         '   <button class="btn   btn-success geturls"'+
                        'mac="'+row.mac+'"'+
                        'data-toggle="modal" data-target="#myModalUrl">'+
                         '   <i class="fa fa-home"></i> 上网行为监控'+
                          '  </button>';
                    }
                }
            ],
            "fnDrawCallback": function ( oSettings ) {
                $(".getapsta").click(function(){
                    var mac = $(this).attr('mac');
                    $("#stainfotr").html('<span class="label label-danger">终端关键信息获取中。。。</span>');
                    $.ajax({
                        url : "{:U('/Home/netlog/UserBehavi','',false)}",
                        type : "post",
                        dataType : "json",
                        data: {mac:mac},
                        timeout:10000,
                        success:function(result){
                            console.log(result);
                            if(result.status){
                                if(result.data.length==0){
                                    $("#stainfotr").html('<span class="label label-danger">该终端没有任何关键信息。</span>');
                                    return;
                                }
                                else{
                                    $("#stainfotr").html('');
                                }
                                var list="";
                                var ip="";
                                var mac="";
                                for(var iloop=0; iloop<result.data.length;iloop++){
                                    var time=typeof result.data[iloop]['time']=="undefined"?"":result.data[iloop]['time'];
                                    list+="<tr class=\"stainfotrs\">\n" +
                                        "        <td style='width: 10%'>"+ (iloop + 1) +"</td>\n" +
                                        "        <td style='width: 10%'>"+ result.data[iloop]['mac'] +"</td>\n" +
                                        "        <td style='width: 10%'>"+ time +"</td>\n" +
                                        "        <td style='width: 20%'><span class=\"label label-success\">"+ result.data[iloop]['appid'] +"</span></td>\n" +
                                        "        <td style='width: 20%'><span class=\"label label-danger\">"+ result.data[iloop]['keytype'] + "</span></td>\n" +
                                        "        <td style='width: 30%'>"+ result.data[iloop]['keyword'] + "</td>\n" +
                                        "  </tr> ";

                                    ip=result.data[iloop]['ip'];
                                    mac=result.data[iloop]['mac'];
                                }
                                $("#myModalLabel").html('['+mac+']终端上网关键信息');

                                var tabdiv ="<table class=\"table table-bordered\">\n" +
                                    "    <tbody><tr>\n" +
                                    "     <th style=\"width: 10px\">编号</th>\n" +
                                    "     <th>终端MAC地址</th>\n" +
                                    "     <th>采集时间</th>\n" +
                                    "     <th>APP应用</th>\n" +
                                    "     <th >关键信息类型</th>\n" +
                                    "     <th>关键信息详情</th>\n" +
                                    "\n" +
                                    "    </tr>\n" +
                                    "\n" +
                                    "\n" + list +
                                    "  </tbody></table>";

                                $("#stainfotr").append(tabdiv);
                            }
                            else {
                                $("#stainfotr").html('<span class="label label-danger">该终端没有任何关键信息。</span>');
                            }
                        },
                        error:function(msg){
                            console.log(msg);      //执行错误
                            $("#stainfotr").html('<span class="label label-danger">该终端没有任何关键信息。</span>');
                        }

                    });
                });


                $(".geturls").click(function(){
                    var mac = $(this).attr('mac');
                    $("#urlinfotr").html('');
                    $("#urlinfotr").html('<span class="label label-danger">终端上网浏览记录获取中。。。</span>');
                    $.ajax({
                        url : "{:U('/Home/netlog/UserSurUrl','',false)}",
                        type : "post",
                        dataType : "json",
                        data: {mac:mac},
                        timeout:10000,
                        success:function(result){
                            console.log(result);
                            if(result.status){
                                if(result.data.length==0){
                                    $("#urlinfotr").html('<span class="label label-danger">该终端没有任何上网浏览记录。</span>');
                                    return;
                                }
                                var list="";

                                for(var iloop=0; iloop<result.data.length;iloop++){
                                    list+="<tr class=\"stainfotrs\">\n" +
                                        "        <td style='width: 10%'>"+ (iloop + 1) +"</td>\n" +
                                        "        <td style='width: 10%'>"+ mac +"</td>\n" +
                                        "        <td style='width: 30%'>"+ result.data[iloop]['url'] + "</td>\n" +
                                        "  </tr> ";

                                }
                                $("#myModalLabelurl").html('['+mac+']终端上网浏览记录');

                                var tabdiv ="<table class=\"table table-bordered\">\n" +
                                    "    <tbody><tr>\n" +
                                    "     <th style=\"width: 10px\">编号</th>\n" +
                                    "     <th>终端MAC地址</th>\n" +
                                    "     <th>上网记录</th>\n" +
                                    "\n" +
                                    "    </tr>\n" +
                                    "\n" +
                                    "\n" + list +
                                    "  </tbody></table>";

                                $("#urlinfotr").append(tabdiv);
                            }
                            else {
                                $("#urlinfotr").html('<span class="label label-danger">该终端没有任何上网浏览记录。</span>');
                            }
                        },
                        error:function(msg){
                            console.log(msg);      //执行错误
                            $("#urlinfotr").html('<span class="label label-danger">该终端没有任何上网浏览记录。</span>');
                        }

                    });
                });

            },
            "oLanguage": {
                "sProcessing": "处理中...",
                "sLengthMenu": "显示 _MENU_ 项结果",
                "sZeroRecords": "没有符合条件的上网日志",
                "sInfo": "显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 个上网日志",
                "sInfoEmpty": "显示第 0 至 0 项结果，共 0 项",
                "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
                "sInfoPostFix": "",
                "sSearch": "搜索:",
                "sUrl": "",
                "sEmptyTable": "没有扫描到任何上网日志信息",
                "sLoadingRecords": "数据加载中...",
                "sInfoThousands": ",",
                "oPaginate": {
                    "sFirst": "首页",
                    "sPrevious": "上页",
                    "sNext": "下页",
                    "sLast": "末页"
                },
                "oAria": {
                    "sSortAscending": ": 以升序排列此列",
                    "sSortDescending": ": 以降序排列此列"
                }
            }
        });
    });

    function getmacalert() {
        $.ajax({
            url : "{:U('/Home/scanwifi/getappearmac','',false)}",
            type : "post",
            dataType : "json",
            data: null,
            timeout:6000,
            success:function(result){
                console.log(result);

                if(result.status==true){
                    $("#macname").html('');
                    for(var iloop=0; iloop<result.data.length;iloop++){
                        $("#macalert").show();
                        $("#macname").append('<h4 >'+
                            '告警标识：' + result.data[iloop]['alertname'] +
                            ' | mac：' + result.data[iloop]['s_mac']+
                            ' 在' + result.data[iloop]['timedesc'] + '出现！</h4>');
                    }
                }
            },
            error:function(msg){
                console.log(msg);
            }
        });
    }
    setInterval(getmacalert, 10000);


</script>

</body>
</html>


